/**
 * @zh-CN 字典格式
 *
 * @param datas
 */

export const formatDict = (data, dictType) => {
  let arr = [];
  data.map(item => {
    if (item.dictType === dictType) {
      arr = item.list || [];
    }
    return '';
  });
  return arr;
};
// export const getValueFromEvent = e => {
//   return e.target.value.replace(/(^\s*)|(\s*$)/g, '');
// };

/**
 * @zh-CN 站点同步树格式
 *
 * @param datas
 */
export const setSiteTreeFormat = datas => {
  const newData = [];
  datas.map(item => {
    const obj = {
      id: item.siteId,
      value: item.siteId,
      pId: item.parentId,
      title: item.siteName,
    };
    if (item.children && item.children.length) {
      obj.children = setSiteTreeFormat(item.children);
    }
    newData.push(obj);
    return '';
  });
  return newData;
};
/**
 * @zh-CN 部门同步树格式
 *
 * @param datas
 */

export const setTreeFormat = datas => {
  const newData = [];

  datas.map(item => {
    const obj = {
      id: item.deptId,
      value: item.deptId,
      pId: item.parentId,
      title: item.deptName,
    };
    if (item.children && item.children.length) {
      obj.children = setTreeFormat(item.children);
    }
    newData.push(obj);
    return '';
  });
  return newData;
};

/**
 * @zh-CN 栏目同步树格式化
 *
 * @param datas
 */

export const setColumnTreeFormat = datas => {
  const newData = [];
  datas.map(item => {
    const obj = {
      id: item.columnId,
      value: item.columnId,
      pId: item.parentId,
      title: item.columnName,
    };
    if (item.children && item.children.length) {
      obj.children = setColumnTreeFormat(item.children);
    }
    newData.push(obj);
    return '';
  });
  return newData;
};
